import { Component } from '@tarojs/taro'
import { Text, View } from '@tarojs/components'
import classNames from 'classnames'
import styles from '../index.module.scss'
import { toGoodsPage } from '@/utils/page_router'
import GoodsImg from '@/components/goods/goods-img/index'
import {getBrand, goodsScore} from '@/utils/storage'
import { PRODUCT_SALES_TEXT } from '@/config/file'

//  获取单位
const getUnit = (number, unit) => {
  return (number > 10000 ? `${Number((number / 10000).toFixed(1))}万${unit}`: `${number}${unit}`)
}

interface IProps {
  info: any
  className?: string
}

export default class GoodsOneItem extends Component<IProps, {}> {
  props: any

  render() {
    const { info={}, className } = this.props
    return (<View className={classNames(styles['goods-item'], className)} onClick={() => toGoodsPage(info)}>
      <View className={styles['goods-img']}>
        <GoodsImg info={info} lazyLoad/>
        {info.salesNumber && <View className={styles['goods-sales']}>{PRODUCT_SALES_TEXT} {getUnit(info.salesNumber, '+')}</View>}
      </View>
      <View className={classNames(styles['goods-name'], 't-o-e-2')}>{info.name}</View>
      <View className={classNames(styles['goods-price'], 'bnn-number')}>
        {goodsScore(info.needScore) &&
        <Text className={styles['goods-price-score']}>{info.needScore}{getBrand()}</Text>}
        <Text className={styles['goods-price-sale']}>
          {goodsScore(info.needScore) && <Text>+</Text>}
          {info.salePrice}元
        </Text>
      </View>
      <View className=''>
        <Text className={classNames(styles['goods-price-origin'], 'bnn-number')}>￥{info.originPrice}</Text>
      </View>
    </View>)
  }
}
